// index.js
Page({
  data: {
    provinces: [
      {
        id: 1,
        name: '直辖市',
        expanded: false,
        cities: [
          { name: '北京', pinyin: 'beijing', lines: 24 },
          { name: '上海', pinyin: 'shanghai', lines: 20 },
          { name: '天津', pinyin: 'tianjin', lines: 9 },
          { name: '重庆', pinyin: 'chongqing', lines: 9 }
        ]
      },
      {
        id: 2,
        name: '广东省',
        expanded: false,
        cities: [
          { name: '广州', pinyin: 'guangzhou', lines: 15 },
          { name: '深圳', pinyin: 'shenzhen', lines: 12 },
          { name: '佛山', pinyin: 'foshan', lines: 2 },
          { name: '东莞', pinyin: 'dongguan', lines: 2 }
        ]
      },
      {
        id: 3,
        name: '江苏省',
        expanded: false,
        cities: [
          { name: '南京', pinyin: 'nanjing', lines: 11 },
          { name: '苏州', pinyin: 'suzhou', lines: 5 },
          { name: '无锡', pinyin: 'wuxi', lines: 4 },
          { name: '常州', pinyin: 'changzhou', lines: 2 }
        ]
      },
      {
        id: 4,
        name: '浙江省',
        expanded: false,
        cities: [
          { name: '杭州', pinyin: 'hangzhou', lines: 10 },
          { name: '宁波', pinyin: 'ningbo', lines: 6 },
          { name: '温州', pinyin: 'wenzhou', lines: 2 }
        ]
      },
      {
        id: 5,
        name: '四川省',
        expanded: false,
        cities: [
          { name: '成都', pinyin: 'chengdu', lines: 13 }
        ]
      },
      {
        id: 6,
        name: '湖北省',
        expanded: false,
        cities: [
          { name: '武汉', pinyin: 'wuhan', lines: 12 }
        ]
      },
      {
        id: 7,
        name: '陕西省',
        expanded: false,
        cities: [
          { name: '西安', pinyin: 'xian', lines: 9 }
        ]
      },
      {
        id: 8,
        name: '山东省',
        expanded: false,
        cities: [
          { name: '青岛', pinyin: 'qingdao', lines: 8 },
          { name: '济南', pinyin: 'jinan', lines: 4 }
        ]
      },
      {
        id: 9,
        name: '福建省',
        expanded: false,
        cities: [
          { name: '福州', pinyin: 'fuzhou', lines: 2 },
          { name: '厦门', pinyin: 'xiamen', lines: 6 }
        ]
      },
      {
        id: 10,
        name: '河南省',
        expanded: false,
        cities: [
          { name: '郑州', pinyin: 'zhengzhou', lines: 7 }
        ]
      },
      {
        id: 11,
        name: '辽宁省',
        expanded: false,
        cities: [
          { name: '沈阳', pinyin: 'shenyang', lines: 4 },
          { name: '大连', pinyin: 'dalian', lines: 5 }
        ]
      },
      {
        id: 12,
        name: '湖南省',
        expanded: false,
        cities: [
          { name: '长沙', pinyin: 'changsha', lines: 6 }
        ]
      },
      {
        id: 13,
        name: '安徽省',
        expanded: false,
        cities: [
          { name: '合肥', pinyin: 'hefei', lines: 5 }
        ]
      },
      {
        id: 14,
        name: '江西省',
        expanded: false,
        cities: [
          { name: '南昌', pinyin: 'nanchang', lines: 4 }
        ]
      }
    ]
  },

  onLoad() {
    // 页面加载完成后添加入场动画
    setTimeout(() => {
      this.setData({
        'provinces[0].expanded': false
      })
    }, 100)
  },

  // 切换省份展开收起状态
  toggleProvince(e) {
    const index = e.currentTarget.dataset.index
    const provinces = this.data.provinces
    
    // 关闭其他省份，只保持一个展开
    provinces.forEach((province, i) => {
      if (i !== index) {
        province.expanded = false
      }
    })
    
    // 切换当前省份状态
    provinces[index].expanded = !provinces[index].expanded
    
    this.setData({
      provinces: provinces
    })
  },

  // 选择城市，跳转到toilet页面
  selectCity(e) {
    const city = e.currentTarget.dataset.city
    console.log('选择城市:', city)
    
    wx.navigateTo({
      url: `/pages/toilet/toilet?city=${city.pinyin}&cityName=${city.name}`
    })
  }
})
